package com.safewind.webService;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import com.safewind.util.PropertiesUtil;

public class SmsService {

	private static String userName = PropertiesUtil.getValue("userName");
	private static String password = PropertiesUtil.getValue("password");
	private static String cid = PropertiesUtil.getValue("cid");
	private static String smsnumber = PropertiesUtil.getValue("smsNumber");
	private static String wsdl = PropertiesUtil.getValue("wsdl");
	private static String getFullMoney = PropertiesUtil
			.getValue("getFullMoney");
	private static String sendNote = PropertiesUtil.getValue("sendNote");
	private static String login = PropertiesUtil.getValue("login");
	private static String editPassword = PropertiesUtil
			.getValue("editPassword");

	public static int sendNote(String phoneNumbers, String content)
			throws Exception {
		java.net.URLEncoder.encode(content, "gbk");
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		Object[] objects;
		objects = client.invoke(sendNote, phoneNumbers, content, userName,
				password, cid, "", smsnumber);
		return Integer.parseInt(objects[0].toString());
//		return 1;
	}

	public static int getUserFullMoney() throws Exception {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		Object[] objects = client.invoke(getFullMoney, userName, password, cid);
		return Integer.parseInt(objects[0].toString());
	}

	public static int userLogin() throws Exception {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		Object[] objects = client.invoke(login, userName, password, cid);
		return Integer.parseInt(objects[0].toString());
	}

	public static int editUserPassword(String newPassword) throws Exception {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsdl);
		Object[] objects = client.invoke(editPassword, userName, password,
				newPassword, cid);
		return Integer.parseInt(objects[0].toString());
	}

}
